﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Script.Serialization;
using System.Web.SessionState;

namespace HQWeb.View
{
    /// <summary>
    /// GetProject 通过项目id获得项目信息
    /// </summary>
    public class GetProject : IHttpHandler, IReadOnlySessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            if (context.Session["BRANCH_ID"] != null)
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                string strID = context.Request["id"];
                string strType = "";
                Dictionary<string, string> dt = null;
                if (context.Request["type"] != null)
                {
                    strType = context.Request["type"];
                }
                if (strType == "6")
                {
                    dt = GetTheme(strID);
                }
                else
                {
                    strID = strID + "-" + context.Session["BRANCH_ID"].ToString();
                    dt = GetProgect(strID);
                }
                context.Response.Write(js.Serialize(dt));
            }
            else
            {
                context.Response.Write("SessionTimeout");
            }
        }
        /// <summary>
        /// 获得文件的主题婚礼
        /// </summary>
        /// <param name="strFileID"></param>
        /// <returns></returns>
        private Dictionary<string, string> GetTheme(string strFileID)
        {
            Dictionary<string, string> dt = new Dictionary<string, string>();
            BLL.Progect.T_PUB_PROJECT bll = new BLL.Progect.T_PUB_PROJECT();
            DataTable tb = bll.GetFileThem(strFileID);
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                dt.Add(tb.Rows[i]["ID"].ToString(), tb.Rows[i]["TITLE"].ToString());
            }
            return dt;
        }

        /// <summary>
        /// 获得文件项目
        /// </summary>
        /// <param name="strID"></param>
        /// <returns></returns>
        private Dictionary<string, string> GetProgect(string strID)
        {
            Dictionary<string, string> dt = new Dictionary<string, string>();
            BLL.Progect.T_PUB_PROJECT bll = new BLL.Progect.T_PUB_PROJECT();
            DataTable tb = bll.GetFileProgect(strID);
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                dt.Add(tb.Rows[i]["PROJECT_ID"].ToString(), tb.Rows[i]["PROJECT_NAME"].ToString());
            }
            return dt;
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}